package com.cq.hd.app.controller;

import com.cq.hd.common.annotation.LoginUser;
import com.cq.hd.common.entity.AppLoginUser;
import com.cq.hd.common.pagination.Page;
import com.cq.hd.common.response.Result;
import com.cq.hd.member.api.TbFeedbackApi;
import com.cq.hd.member.api.dto.AppFeedbackPageDto;
import com.cq.hd.member.api.dto.FeedbackPageDto;
import com.cq.hd.member.api.dto.FeedbackSaveDto;
import com.cq.hd.member.api.vo.FeedbackPageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

@RestController
@RequestMapping("/feedback")
@Api(tags = "反馈建议相关接口")
public class FeedbackController {

    @Autowired
    private TbFeedbackApi feedbackApi;

    @ApiOperation(value = "提交反馈建议")
    @ApiImplicitParam(name = "feedbackSaveDto", value = "实体", required = true, paramType = "body", dataType = "FeedbackSaveDto")
    @PostMapping("/save")
    public Result<Boolean> saveFeedback(@RequestBody FeedbackSaveDto feedbackSaveDto, @ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        feedbackSaveDto.setUserId(appLoginUser.getUserId());
        return feedbackApi.saveFeedback(feedbackSaveDto);
    }

    @ApiOperation(value = "反馈记录列表")
    @ApiImplicitParam(name = "appFeedbackPageDto", value = "实体", required = true, paramType = "body", dataType = "AppFeedbackPageDto")
    @ApiResponse(response = FeedbackPageVo.class, code = 200, message = "接口返回对象参数")
    @GetMapping("/page")
    public Result<Page<FeedbackPageVo>> page(AppFeedbackPageDto appFeedbackPageDto, @ApiIgnore @LoginUser AppLoginUser appLoginUser) {
        FeedbackPageDto feedbackPageDto = new FeedbackPageDto();
        BeanUtils.copyProperties(appFeedbackPageDto, feedbackPageDto);
        feedbackPageDto.setUserId(appLoginUser.getUserId());
        return feedbackApi.pageFeedback(feedbackPageDto);
    }

}
